package com.gongye.courseselectionsystem.controller;

import com.gongye.courseselectionsystem.constants.ResultCodeEnum;
import com.gongye.courseselectionsystem.pojo.vo.ResultList;
import com.gongye.courseselectionsystem.service.AddCourseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author baorongchuan
 */
@Slf4j
@RestController
@Api(tags = "学生创建选课接口")
@RequestMapping("/add")
public class AddCourseController {
    @Resource
    private AddCourseService addCourseService;

    @ApiImplicitParams({@ApiImplicitParam(name = "courseNumber", value = "课程编号", dataType = "integer", paramType = "insert"),
            @ApiImplicitParam(name = "studentNumber", value = "学生编号", dataType = "integer", paramType = "insert"),
            @ApiImplicitParam(name = "teacherJobNumber", value = "教师工号", dataType = "integer", paramType = "insert")
    })
    @ApiOperation(value = "选课接口", notes = "选课接口", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/course", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResultList addCourse(@RequestParam("courseNumber") Integer courseNumber,
                                @RequestParam("studentNumber") Integer studentNumber,
                                @RequestParam("teacherJobNumber") Integer teacherJobNumber) {
        try {
            return addCourseService.addCourse(courseNumber, studentNumber, teacherJobNumber);
        } catch (Exception e) {
            return new ResultList(ResultCodeEnum.FAILED, e.getMessage());
        }
    }
}
